package com.mall.web.controller;

import com.alibaba.fastjson2.JSONObject;
import com.mall.base.pojo.Product;
import com.mall.base.pojo.VersionInfo;
import com.mall.web.service.product.ProductService;
import com.mall.web.service.product.VersionInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 游政杰
 */
@Controller
@RequestMapping(path = "/web/product")
@Api("商品服务 web api")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    private VersionInfoService versionInfoService;


    @ResponseBody
    @GetMapping(path = "/selectAllProduct",produces = "application/json; charset=utf-8")
    public String selectAllProduct(){
        List<Product> products = productService.selectAllProduct();
        List<VersionInfo> versionInfos = versionInfoService.selectAllVersionInfo();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("products",products);
        jsonObject.put("versions_info",versionInfos);
        return jsonObject.toJSONString();
    }


//    @ResponseBody
//    @GetMapping(path = "/selectIntroduceByPid/{pid}")
//    public String[] selectIntroduceByPid(@PathVariable("pid") long pid){
//
//        String imgs[] = productFallbackFeign.selectIntroduceByPid(pid);
//
//        return imgs;
//    }



}
